
#ifndef __TARGET_H__
#define __TARGET_H__

//
typedef unsigned int mem_addr_t;
typedef struct
{
    void (*erase)(void);
    void (*init)(void);
    void (*program)(void);
    void (*read)(void);
    void (*erase_chip)(void);
    void (*get_info)(void);
} target_flashalgo_t;

typedef struct
{
    int (*read_reg)(unsigned char *regval, unsigned int regno, unsigned int _regsz);
    int (*write_reg)(unsigned char *regval, unsigned int regno, unsigned int _regsz);
    int (*read_mem)(mem_addr_t addr, char *buf, unsigned int sz);
    int (*write_mem)(mem_addr_t addr, char *buf, unsigned int sz);
    int (*breakpiont)(unsigned char *addr, char point_type, char set_clr); // 硬件断点 软件断点 观察点等的设置或清除
    int (*halt_reason)(void);
    int (*reset)(char flag);  // 设置标志 复位后是否挂起
    int (*step)(char flag); 
    int (*resume)(unsigned char *addr, char flag); // 设置标志 从指定地址运行
    int (*halt)(void);
    void (*init)(void);

    target_flashalgo_t flash;

    unsigned int idcode;
    unsigned int err;
    char endian;
    char xlen;
    char probe;
} target_t;

extern int target_riscv_init(target_t *_target);

#endif
